/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package planspiel;

import javax.swing.JLabel;

/**
 * 
 * @author Administrator
 */
public class CountdownTimer extends AbstractTimer {
	
    /**
     * 
     * @return
     */
    public String getRestzeitAsString() {
		int sec = getRestzeit() % 60;
		int min = (getRestzeit() - sec) / 60;
		String minString = "00" + min;
		String secString = "00" + sec;
		return minString.substring(minString.length() - 2, minString.length())
				+ ":" + secString.substring(secString.length() - 2, secString.length());
	}
	

        /**
         * 
         */
        @Override
	public void fireChangedEvent() {
            for (JLabel each: changedListener) {
                    // Bei besserer Entkopplung ruft man hier die Callback-Methode eines Interfaces auf
                    each.setText(getRestzeitAsString());
            }
            if (getRestzeit() <= 0) {
                    getTimer().cancel();
                    fireFinishedEvent();
            }
	}

        /**
         * 
         */
        @Override
	public void fireFinishedEvent() {
            for (JLabel each: finishedListener) {
                each.setText("Fertig!");
            }
	}

}
